home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / mma2ltx / mmatext.sty < prev    next >
Text File  |  1994-07-17  |  10KB  |  281 lines

  1. %
  2. % macros for picture produced by "mma2ltx"
  3. % version 1.2 - 18 July 1994
  4. %
  5. % Copyright (C) 1994 by Giuseppe Ghib\`o (<ghibo@galileo.polito.it>)
  6. %
  7. % ----------------------------------------------------------------------------
  8. %
  9. \typeout{Document Style `mmatext' - v1.2 (18/7/94) - (C) 1994 by Giuseppe Ghibo`}
  10. %
  11. \gdef\mma@prologue{texmma22.pro}% Mathematica v2.2 PostScript prologue file.
  12. %
  13. %
  14. \newdimen\mma@tmpdima
  15. \newdimen\mma@tmpdimb
  16. \newdimen\mma@tmpdimc
  17. \newdimen\mma@tmpdimd
  18. \newbox\mma@tmpbox
  19. %
  20. %
  21. % \mmaheaderprotrue   = include the prologue file \mma@prologue (once) using
  22. %                       the \special{header=...}.
  23. % \mmaheaderprofalse  = don't include the prologue file \mma@prologue.
  24. % \mma@proloadedtrue  = the prologue \mma@prologue has been already loaded.
  25. % \mma@proloadedfalse = the prologue \mma@prologue has not been loaded.
  26. % \mma@whitebgtrue    = the object will have a white background
  27. % \mma@whitebgfalse   = the object will have a transparent background
  28. \newif\ifmmaheaderpro  \mmaheaderprotrue
  29. \newif\ifmma@proloaded \mma@proloadedfalse
  30. \newif\ifmma@whitebg
  31. %
  32. %
  33. % \@nameedef is similar to the LaTeX command \@namedef, but it uses \edef
  34. % instead of \def.
  35. \def\@nameedef#1{\expandafter\edef\csname #1\endcsname}
  36. %
  37. \let\ccd=\catcode
  38. \ccd`\p=12\ccd`\t=12
  39. \def\del@dim#1pt{#1}%
  40. \ccd`\p=11\ccd`\t=11
  41. %
  42. \def\deldim#1{\expandafter\del@dim\the#1}%trash the trailing 'pt'
  43. \def\dimtomac#1#2#3{%
  44. % \dimtomac (expands a dimension register into a macro)
  45. % #1 = a dimension register (e.g., \mydim, \dimen0, ...)
  46. % #2 = conversion factor from pt to a choosed unit or
  47. %      one of mm, cm, pt, bp, pc, in, dd, cc, sp, dbp.
  48. % #3 = macro to which assign the converted value.
  49. \lowercase{\edef\convfactor{#2}}
  50. \def\unit@mm{mm}\def\unit@cm{cm}\def\unit@pt{pt}\def\unit@bp{bp}%
  51. \def\unit@pc{pc}\def\unit@in{in}\def\unit@dd{dd}\def\unit@cc{cc}%
  52. \def\unit@sp{sp}\def\unit@dbp{dbp}%
  53. \ifx\convfactor\unit@mm\def\convfactor{0.3514598035146}\else
  54. \ifx\convfactor\unit@cm\def\convfactor{0.03514598035146}\else
  55. \ifx\convfactor\unit@pt\def\convfactor{1}\else
  56. \ifx\convfactor\unit@bp\def\convfactor{0.99626400996264}\else
  57. \ifx\convfactor\unit@dbp\def\convfactor{9.962640996264}\else
  58. \ifx\convfactor\unit@pc\def\convfactor{0.08333333333333}\else
  59. \ifx\convfactor\unit@in\def\convfactor{0.01383700013837}\else
  60. \ifx\convfactor\unit@dd\def\convfactor{0.9345718901454}\else
  61. \ifx\convfactor\unit@cc\def\convfactor{0.077880990845450}\else
  62. \fi\fi\fi\fi\fi\fi\fi\fi\fi
  63. \mma@tmpdima=#1%
  64. \ifx\convfactor\unit@sp\@nameedef{#3}{\number\mma@tmpdima}\else
  65. \mma@tmpdimb=\convfactor\mma@tmpdima%
  66. \@nameedef{#3}{\deldim\mma@tmpdimb}\fi
  67. }% end of dimtomac definition
  68. %
  69. %
  70. \newdimen\mma@dimunit \mma@dimunit=1bp
  71. \newdimen\mma@llx \newdimen\mma@urx \newdimen\mma@width  \newdimen\mma@oldwd
  72. \newdimen\mma@lly \newdimen\mma@ury \newdimen\mma@height \newdimen\mma@oldht
  73. \newdimen\mma@x \newdimen\mma@y
  74. \newdimen\mma@deltax \newdimen\mma@deltay
  75. %
  76. \gdef\mma@wd{161}%  default width in bp
  77. \gdef\mma@ht{100}%  default height in bp
  78. \gdef\mma@unit{bp}% default unit = bp
  79. \mma@width=\mma@wd bp
  80. \mma@height=\mma@ht bp
  81. \mma@llx=\z@ \mma@urx=\mma@width
  82. \mma@lly=\z@ \mma@ury=\mma@height
  83. \mma@deltax=\z@ \mma@deltay=\z@
  84. %
  85. %
  86. % *************
  87. % *           *
  88. % * mmasetpic *
  89. % *           *
  90. % *************
  91. \def\mmasetpic(#1,#2){\@ifnextchar({\mma@oldsetpic(#1,#2)}{%
  92. \mma@setpic(#1,#2)}}
  93.  
  94. \def\mma@setpic(#1,#2)[#3]#4{%
  95. % #1 = width of Mathematica PostScript picture
  96. % #2 = height of Mathematica PostScript picture
  97. % #3 = unit of measure
  98. % #4 = PostScript filename
  99. \lowercase{\edef\mma@unit{#3}}
  100. \mma@dimunit=1\mma@unit
  101. \mma@llx=\z@ \mma@urx=#1\mma@dimunit
  102. \mma@lly=\z@ \mma@ury=#2\mma@dimunit
  103. \mma@width=#1\mma@dimunit \mma@height=#2\mma@dimunit
  104. \mma@oldwd=\mma@width \mma@oldht=\mma@height
  105. \dimtomac{\mma@oldwd}{bp}{mma@wd}
  106. \dimtomac{\mma@oldht}{bp}{mma@ht}
  107. \def\mma@psname{#4}
  108. %
  109. % include the prologue file \mma@prologue at most once.
  110. \ifmma@proloaded\else
  111. \ifmmaheaderpro\special{header=texmma22.pro}\global\mma@proloadedtrue\fi
  112. \fi
  113. }
  114. %
  115. %
  116. % ***************
  117. % *             *
  118. % * mmatextfits *
  119. % *             *
  120. % ***************
  121. \def\mmatextfits(#1,#2)(#3,#4){\@ifnextchar({\mma@textfits(#1,#2)(#3,#4)}{%
  122.         \mma@textfits(#1,#2)(#3,#4)(0,0)}}
  123. %
  124. \def\mma@textfits(#1,#2)(#3,#4)(#5,#6)#7{%
  125. % #1 = x coord.
  126. % #2 = y coord.
  127. % #3 = sdx (bounding box x offs., like the Mathematica command "Text")
  128. % #4 = sdx (bounding box y offs., like the Mathematica command "Text")
  129. % #5 = offset to the x coord.
  130. % #6 = offset to the y coord.
  131. % #7 = text to fit.
  132. \setbox\mma@tmpbox=\hbox{#7}
  133. %
  134. % tmpllx = x - 1/2*wd*(sdx+1)
  135. \mma@tmpdima=#1\mma@dimunit \advance\mma@tmpdima by #5\mma@dimunit
  136. \mma@tmpdimb=#3\wd\mma@tmpbox
  137. \advance\mma@tmpdimb by \wd\mma@tmpbox
  138. \divide\mma@tmpdimb by 2
  139. \advance\mma@tmpdima by -\mma@tmpdimb
  140. \ifdim\mma@tmpdima < \mma@llx \mma@llx=\mma@tmpdima\fi
  141. %
  142. % tmplly = y - 1/2*(ht+dp)*(sdy+1)
  143. \mma@tmpdima=#2\mma@dimunit \advance\mma@tmpdima by #6\mma@dimunit
  144. \mma@tmpdimb=\ht\mma@tmpbox
  145. \advance\mma@tmpdimb by \dp\mma@tmpbox
  146. \mma@tmpdimb=#4\mma@tmpdimb
  147. \advance\mma@tmpdimb by \ht\mma@tmpbox
  148. \advance\mma@tmpdimb by \dp\mma@tmpbox
  149. \divide\mma@tmpdimb by 2
  150. \advance\mma@tmpdima by -\mma@tmpdimb
  151. \ifdim\mma@tmpdima < \mma@lly \mma@lly=\mma@tmpdima\fi
  152. %
  153. % tmpurx = x - 1/2*wd*(sdx-1)
  154. \mma@tmpdima=#1\mma@dimunit \advance\mma@tmpdima by #5\mma@dimunit
  155. \mma@tmpdimb=#3\wd\mma@tmpbox
  156. \advance\mma@tmpdimb by -\wd\mma@tmpbox
  157. \divide\mma@tmpdimb by 2
  158. \advance\mma@tmpdima by -\mma@tmpdimb
  159. \ifdim\mma@tmpdima > \mma@urx \mma@urx=\mma@tmpdima\fi
  160. %
  161. % tmpury = y - 1/2*(ht+dp)*(sdy-1)
  162. \mma@tmpdima=#2\mma@dimunit \advance\mma@tmpdima by #6\mma@dimunit
  163. \mma@tmpdimb=\ht\mma@tmpbox
  164. \advance\mma@tmpdimb by \dp\mma@tmpbox
  165. \mma@tmpdimb=#4\mma@tmpdimb
  166. \advance\mma@tmpdimb by -\ht\mma@tmpbox
  167. \advance\mma@tmpdimb by -\dp\mma@tmpbox
  168. \divide\mma@tmpdimb by 2
  169. \advance\mma@tmpdima by -\mma@tmpdimb
  170. \ifdim\mma@tmpdima > \mma@ury \mma@ury=\mma@tmpdima\fi
  171. %
  172. % Recalculate new picture size
  173. \mma@width=\mma@urx \advance\mma@width by -\mma@llx
  174. \mma@height=\mma@ury \advance\mma@height by -\mma@lly
  175. \mma@deltax=\mma@width \advance\mma@deltax by -\mma@oldwd
  176. \mma@deltay=\mma@height \advance\mma@deltay by -\mma@oldht
  177. }% end of \mmatextfits definition
  178. %
  179. %
  180. % **************
  181. % *            *
  182. % * mmapicture *
  183. % *            *
  184. % **************
  185. \def\mmapicture{%
  186. \bgroup
  187. \unitlength=1sp% so we can use the command \number
  188. \dimtomac{\mma@width}{\mma@unit}{mma@truewd}
  189. \dimtomac{\mma@height}{\mma@unit}{mma@trueht}
  190. \dimtomac{\mma@deltax}{\mma@unit}{mma@dx}
  191. \dimtomac{\mma@deltay}{\mma@unit}{mma@dy}
  192. \typeout{Mathematica  picture:\space'\mma@psname'\space%
  193.     size=(\mma@truewd\space x\space\mma@trueht\space\mma@unit)}
  194. \ifdim\mma@deltax > 0pt
  195.    \typeout{Mathematica picture:\space'\mma@psname'\space%
  196.             deltax=\mma@dx\space\mma@unit}
  197. \fi
  198. \ifdim\mma@deltay > 0pt
  199.    \typeout{Mathematica picture:\space'\mma@psname'\space%
  200.             deltay=\mma@dy\space\mma@unit}
  201. \fi
  202. \@killglue
  203. \begin{picture}(\number\mma@width,\number\mma@height)(\number\mma@llx,\number\mma@lly)
  204. \put(0,0){\special{psfile=\mma@psname\space hsize=\mma@wd\space vsize=\mma@ht}}}
  205. %
  206. \def\endmmapicture{\end{picture}\egroup}
  207. %
  208. %
  209. % **************
  210. % *            *
  211. % * mmaputtext *
  212. % *            *
  213. % **************
  214. \def\mmaputtext{\@ifstar{\mma@whitebgtrue\mma@puttext}{\mma@whitebgfalse%
  215. \mma@puttext}}
  216.  
  217. \def\mma@puttext(#1,#2)(#3,#4){\@ifnextchar({\mma@@puttext(#1,#2)(#3,#4)}{%
  218.         \mma@@puttext(#1,#2)(#3,#4)(0,0)}}
  219. %
  220. \def\mma@@puttext(#1,#2)(#3,#4)(#5,#6)#7{%
  221. % #1 = x coord.
  222. % #2 = y coord.
  223. % #3 = sdx (bounding box x offs., like the command "Text" of Mathematica)
  224. % #4 = sdx (bounding box y offs., like the command "Text" of Mathematica)
  225. % #5 = offset to the x coord.
  226. % #6 = offset to the y coord.
  227. % #7 = text (or object) to put.
  228. %
  229. \setbox\mma@tmpbox=\hbox{#7}
  230. \mma@x=#1\mma@dimunit \advance\mma@x by #5\mma@dimunit
  231. \mma@y=#2\mma@dimunit \advance\mma@y by #6\mma@dimunit
  232. %
  233. % xp = x - 1/2 * wd * (sdx + 1)
  234. \mma@tmpdima=#3\wd\mma@tmpbox
  235. \advance\mma@tmpdima by \wd\mma@tmpbox
  236. \divide\mma@tmpdima by 2
  237. \advance\mma@x by -\mma@tmpdima
  238. %
  239. % yp = y - 1/2*(sdy*htot + ht - dp)
  240. \mma@tmpdima=\ht\mma@tmpbox
  241. \advance\mma@tmpdima by \dp\mma@tmpbox
  242. \mma@tmpdima=#4\mma@tmpdima
  243. \advance\mma@tmpdima by \ht\mma@tmpbox
  244. \advance\mma@tmpdima by -\dp\mma@tmpbox
  245. \divide\mma@tmpdima by 2
  246. \advance\mma@y by -\mma@tmpdima
  247. %
  248. \mma@tmpdimc=\dp\mma@tmpbox
  249. \ifmma@whitebg
  250. \mma@tmpdimc=\wd\mma@tmpbox
  251. \mma@tmpdimd=\ht\mma@tmpbox \advance\mma@tmpdimd by \dp\mma@tmpbox
  252. \dimtomac{\mma@tmpdimc}{bp}{mma@tmpwd}
  253. \dimtomac{\mma@tmpdimd}{bp}{mma@tmpht}
  254. \advance\mma@y by -\dp\mma@tmpbox% special{psfile=mmawhite.eps...} has zero depth
  255. \put(\number\mma@x,\number\mma@y){\makebox(0,0)[lb]{\special{psfile=mmawhite.eps\space hsize=\mma@tmpwd\space vsize=\mma@tmpht}}}
  256. \advance\mma@y by \dp\mma@tmpbox\fi
  257. \put(\number\mma@x,\number\mma@y){\makebox(0,0)[lb]{\box\mma@tmpbox}}
  258. }% end of \mma@puttext definition
  259. %
  260. %
  261. % For compatibility with mma2ltx v1.03
  262. \def\mmashowunit#1{\gdef\mma@unit{#1}\global\mma@dimunit=1bp}
  263. %
  264. %
  265. % For compatibility with mma2ltx v1.03
  266. \def\mma@oldsetpic(#1,#2)(#3,#4,#5,#6)#7{%
  267. % #1 = width of Mathematica PostScript picture in bp
  268. % #2 = height of Mathematica PostScript picture in bp
  269. % #3,#4,#5,#6 = transformation matrix (never used).
  270. % #7 = PostScript filename
  271. %
  272. \mma@llx=\z@ \mma@urx=#1\mma@dimunit
  273. \mma@lly=\z@ \mma@ury=#2\mma@dimunit
  274. \mma@width=#1\mma@dimunit \mma@height=#2\mma@dimunit
  275. \mma@oldwd=\mma@width \mma@oldht=\mma@height
  276. \gdef\mma@wd{#1} \gdef\mma@ht{#2}
  277. \gdef\mma@psname{#7}
  278. \ifmma@proloaded\else\special{header=texmma22.pro}\global\mma@proloadedtrue\fi
  279. }% end of mmasetpic definition
  280.